//上传头像
$('#file').on('change',function(){
 var file = this.files[0];
 var formData = new FormData();
 formData.append('logo',file);
 $.ajax({
     type:'post',
     url:'/upload',
     data:formData,
     processData:false,
     contentType:false,
     success:function(response){
         $('#hiddenLogo').val(response[0].logo);
         $('#preview').attr('src',response[0].logo);
     }
 });
})

//添加设置信息
$('#settingForm').on('submit',function(){
    var formData = $(this).serialize();
    $.ajax({
        type:'post',
        url:'/settings',
        data:formData,
        success:function(){
            location.reload();
        }
    });
});

//获取数据 显示在页面中
$.ajax({
   type:'get',
   url:'/settings',
   success:function(response){
       //将logo地址存储在隐藏域中
       $('#hiddenLogo').val(response.logo);
       //将logo显示在页面中
       $('#preview').attr('src',response.logo);
       $('input[name="title"]').val(response.title);
       $('input[name="comment"]').prop('checked',response.comment);
       $('input[name="review"]').prop('checked',response.review);
   } 
});